import { UserProfilesAPI } from '@/request/api';

export default{
    namespaced: true,
    state: {
        userInfo:{
            nickName:'',
            coin:"",
            headImg:require('../../assets/img/userImg.f8bbec5e.png')
        },
        cartTotal:""
    },
    mutations: {
        changeUserInfo(state,payload){
            console.log('修改vuex中用户信息',payload);
            state.userInfo=payload.userInfo;
            state.cartTotal=payload.cartTotal;
        },
        // 初始化
        initUserInfo(state){
            console.log('初始化信息...');
            state.userInfo={
                nickName:'',
                coin:0,
            headImg:require('../../assets/img/userImg.f8bbec5e.png')
            }
            state.cartTotal=0;
        }


    },
    actions: {
        async asyncChangeUserInfo(context){
            let user =await UserProfilesAPI();
            console.log('user',user.data);

            // 调用mutations更新用户信息
            context.commit('changeUserInfo',user.data)
        }
    }
}